// sys-user.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { SysRole } from './sys-role.entity';

@Entity('sys_user')
export class SysUser {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'varchar', length: 64, unique: true, nullable: true, comment: '用户名' })
  username: string;

  @Column({ type: 'varchar', length: 64, nullable: true, comment: '昵称' })
  nickname: string;

  @Column({ type: 'tinyint', default: 1, comment: '性别' })
  gender: number;

  @Column({ type: 'varchar', length: 100, nullable: true, comment: '密码' })
  password: string;

  @Column({ type: 'int', nullable: true, comment: '部门ID' })
  dept_id: number;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '用户头像' })
  avatar: string;

  @Column({ type: 'varchar', length: 20, nullable: true, comment: '联系方式' })
  mobile: string;

  @Column({ type: 'boolean', default: true, comment: '状态' })
  status: boolean;

  @Column({ type: 'varchar', length: 128, nullable: true, comment: '用户邮箱' })
  email: string;

 @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
  })
  create_time: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
  })
  update_time: Date;

  @Column({ type: 'bigint', nullable: true, comment: '创建人ID' })
  create_by: number;

  @Column({ type: 'bigint', nullable: true, comment: '修改人ID' })
  update_by: number;

  @Column({ type: 'boolean', default: false, comment: '逻辑删除标识' })
  is_deleted: boolean;

  @Column({ type: 'char', length: 28, nullable: true, comment: '微信 openid' })
  openid: string;

  @ManyToMany(() => SysRole)
  @JoinTable({
    name: 'sys_user_role',
    joinColumn: { name: 'user_id' },
    inverseJoinColumn: { name: 'role_id' },
  })
  roles: SysRole[];
}